﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Core.Utils;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAL.JObject;
using Framework.Library.Data.DAO;
using ServiceStack.Text;
using Framework.Library.Core.Utils.Images;

namespace Framework.Portal.Layouts.Client.Components.Teenio
{
    public partial class EventCategories : BaseControl
    {
        public string MENUNAME = string.Empty;

        public EventCategories()
        {
        }

        public EventCategories(JSection section)
        {
            if (!string.IsNullOrEmpty(section.parameter))
            {
                string[] arrParams = section.parameter.Split('&');
                if (arrParams.Length > 0)
                    menuId = Convert.ToInt32(arrParams[0].Split('=')[1]);
                if (arrParams.Length > 1)
                    catId = Convert.ToInt32(arrParams[1].Split('=')[1]);
            }
            MENUNAME = section.title;
        }

        protected static int catId = 0;
        protected static int menuId = 0;
        protected static int curMenu = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<TeenioZone> lstContent = ManagerFactory.DAOEntity.GetList(new TeenioZone() { TYPE = 2 });
                if (lstContent != null)
                {
                    rptContent.DataSource = lstContent;
                    rptContent.DataBind();
                }
            }
        }

        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var info = (TeenioZone)e.Item.DataItem;
                var imgAvatar = (Image)e.Item.FindControl("imgAvatar");
                var hplTitle = (HyperLink)e.Item.FindControl("hplTitle");
                //var lblCreateDate = (Literal)e.Item.FindControl("lblCreateDate");
                var lblTeaser = (Literal)e.Item.FindControl("lblTeaser");

                if (!string.IsNullOrEmpty(info.IMAGE))
                    imgAvatar.ImageUrl = ImagesUtils.GetImage(info.IMAGE, 110, 90);
                hplTitle.Text = info.NAME;
                hplTitle.NavigateUrl = cfg.EventPath(info.PORTALID, menuId, info.ID);
                //lblCreateDate.Text = DateTimeHelper.formatDateTime(info.CONTENT_MODIFYDDATE);
                lblTeaser.Text = ConvertUtility.ToSubString(info.DESCRIPTION, 260);
            }
        }
    }
}